package com.chenfan.mcn.model.dto;

import com.chenfan.mcn.model.ApprovalFlow;
import com.chenfan.process.dto.ApprovalCallBack;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author 2062
 */
@SuppressWarnings("AlibabaPojoNoDefaultValue")
@Data
@EqualsAndHashCode(callSuper = true)
public class ApprovalFlowDTO extends ApprovalFlow {

    /**
     * 下个节点审批人ID集合
     */
    private List<String> nextApprovalUserId;

    /**
     * 下个节点审批人集合
     */
    private List<String> nextApprovalUserName;

    /**
     * 源单号（即：业务单号）
     */
    private String srcCode;

    /**
     * 审批事件类型
     */
    private Integer eventType;

    /**
     * 当前审批节点名
     */
    private String nodeName;

    /**
     * 当前审批人ID
     */
    private Long approvalUserId;

    /**
     * 当前审批人
     */
    private String approvalUserName;

    private AtomicBoolean shutdown = new AtomicBoolean(false);

    /**
     * 审批节点抄送
     */
    private List<ApprovalCallBack.CarbonCopyDTO> carbonCopyList;

    public List<ApprovalCallBack.CarbonCopyDTO> getCarbonCopyList() {
        if (CollectionUtils.isEmpty(carbonCopyList)) {
            return carbonCopyList;
        }
        if (shutdown.compareAndSet(false,true)){
            return carbonCopyList;
        }
        return null;
    }
}
